# Maintainer: The MyPaint Team <mypaintopensource@gmail.com>

_realname=mypaint
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=2.0.0alpha
pkgrel=1
provides=(
    "${MINGW_PACKAGE_PREFIX}-${_realname}"
)
conflicts=(
    "${MINGW_PACKAGE_PREFIX}-${_realname}"
)
arch=('any')
pkgdesc="Simple drawing & painting program that works well with Wacom-style graphics tablets (git)"
depends=(
    "${MINGW_PACKAGE_PREFIX}-libmypaint-git"
    "${MINGW_PACKAGE_PREFIX}-gtk3"
    "${MINGW_PACKAGE_PREFIX}-python3-numpy"
    "${MINGW_PACKAGE_PREFIX}-json-c"
    "${MINGW_PACKAGE_PREFIX}-lcms2"
    "${MINGW_PACKAGE_PREFIX}-python3-cairo"
    "${MINGW_PACKAGE_PREFIX}-python3-gobject"
    "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
    "${MINGW_PACKAGE_PREFIX}-librsvg"
    "${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
    "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
    "${MINGW_PACKAGE_PREFIX}-mypaint-brushes2"
)
makedepends=(
    "${MINGW_PACKAGE_PREFIX}-swig"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-pygobject-devel"
    "${MINGW_PACKAGE_PREFIX}-python3"
    "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
    "swig"
)
options=('!strip' 'debug' 'staticlibs')
license=("GPL2")
url="http://mypaint.org"
install=mypaint-${CARCH}.install
source=("${_realname}::git+https://github.com/mypaint/mypaint.git")
sha256sums=('SKIP')

pkgver() {
    cd "${srcdir}"/${_realname}
    eval `python3 lib/meta.py`
    echo "$MYPAINT_VERSION_CEREMONIAL" \
      | sed 's,-\(alpha\),\1.'`date +d%Y%m%d`',' \
      | sed 's,-\(beta\|rc\),\1,' \
      | sed 's,+git[a-z]*\.\?,.g,' \
      | sed 's,-,_,g'
}

prepare() {
    cd "${srcdir}"/${_realname}
}

build() {
    cd "${srcdir}/${_realname}"
    ${MINGW_PREFIX}/bin/python3 setup.py clean --all
    REL_BRUSH_PATH=".${MINGW_PREFIX}/share/mypaint-data/2.0/brushes"
    ${MINGW_PREFIX}/bin/python3 setup.py build_config --brushdir-path="${REL_BRUSH_PATH}" build
}

package() {
    cd "${srcdir}/${_realname}"
    echo "prefix: ${MINGW_PREFIX}"
    echo "root: ${pkgdir}"

    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install \
	--prefix=${MINGW_PREFIX} --root="${pkgdir}" \
	--optimize=1 \
	--skip-build

    # Fix Python #! to not refer to Windows paths (C:\mymsys32\...)
    local PREFIX_WIN=$(cygpath -wm "${MINGW_PREFIX}")
    for script in "${pkgdir}${MINGW_PREFIX}/bin"/mypaint*; do
        sed -e "s|^\(#!.*\)${PREFIX_WIN}/bin/|\1/usr/bin/env |g" -i "$script"
    done

    install -Dm644 COPYING \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
    install -Dm644 Licenses.md \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/Licenses.md"
    install -Dm644 Licenses.dep5 \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/Licenses.dep5"
}
